﻿using System;
using UnityEngine;

public class EditorFactory
{
    public static EditorFactory Instance
    {
        get
        {
            if (instance == null)
                instance = new EditorFactory();

            return instance;
        }
    }
    static EditorFactory instance;

    public UnitEditor Create<T>(GameObject go, GameObject uiGo, T u) where T : Unit, new()
    {
        UnitBehaviour ub = null;
        UnitEditor e = null;

        if (u is Gear)
        {
            ub = go.AddComponent<GearBehaviour>();
            e = uiGo.AddComponent<GearEditor>();
        }
        else if (u is Stick)
        {
            ub = go.AddComponent<StickBehaviour>();
            e = uiGo.AddComponent<StickEditor>();
        }
        else if (u is PowerSource)
        {
            ub = go.AddComponent<PowerSourceBehaviour>();
            e = uiGo.AddComponent<PowerSourceEditor>();
        }

        ub.Unit = u;
        e.UB = ub;
        return e;
    }
}
